home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / autoarrow.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  9KB  |  313 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "func.h"
  13. #include "object.h"
  14. #include "paintop.h"
  15.  
  16. #define            TOLERANCE    7
  17.  
  18. extern            (*canvas_kbd_proc)();
  19. extern            (*canvas_locmove_proc)();
  20. extern            (*canvas_leftbut_proc)();
  21. extern            (*canvas_middlebut_proc)();
  22. extern            (*canvas_rightbut_proc)();
  23. extern            null_proc();
  24. extern            set_popupmenu();
  25. extern F_line        *line_point_search();
  26. extern F_spline        *spline_point_search();
  27. extern F_arc        *arc_point_search();
  28. extern F_arrow        *forward_arrow(), *backward_arrow();
  29.  
  30. extern int        foreground_color, background_color;
  31. extern int        pointmarker_shown;
  32.  
  33. F_point            *selected_point, *left_point;
  34. int            arcpoint_num;
  35.             add_arrow_head();
  36.             delete_arrow_head();
  37.  
  38. #define            round(x)    ((int) (x + .5))
  39.  
  40. arrow_head_selected()
  41. {
  42.     canvas_kbd_proc = null_proc;
  43.     canvas_locmove_proc = null_proc;
  44.     canvas_leftbut_proc = add_arrow_head;
  45.     canvas_middlebut_proc = delete_arrow_head;
  46.     canvas_rightbut_proc = set_popupmenu;
  47.     set_cursor(&pick9_cursor);
  48.     }
  49.  
  50. add_arrow_head(x, y)
  51. int    x, y;
  52. {
  53.     F_line        *line;
  54.     F_spline    *spline;
  55.     F_arc        *arc;
  56.  
  57.     if ((line = line_point_search(x, y, TOLERANCE,
  58.         &left_point, &selected_point)) != NULL) {
  59.         add_linearrow(line);
  60.         }
  61.     else if ((spline = spline_point_search(x, y, 
  62.         TOLERANCE, &left_point, &selected_point)) != NULL){
  63.         add_splinearrow(spline);
  64.         }
  65.     else if ((arc = arc_point_search(x, y, TOLERANCE, 
  66.         &arcpoint_num)) != NULL) {
  67.         add_arcarrow(arc);
  68.         }
  69.     else
  70.         return;
  71.  
  72.     set_modifiedflag();
  73.     }
  74.  
  75. delete_arrow_head(x, y)
  76. int    x, y;
  77. {
  78.     F_line        *line;
  79.     F_spline    *spline;
  80.     F_arc        *arc;
  81.  
  82.     if ((line = line_point_search(x, y, TOLERANCE,
  83.         &left_point, &selected_point)) != NULL) {
  84.         delete_linearrow(line);
  85.         }
  86.     else if ((spline = spline_point_search(x, y, 
  87.         TOLERANCE, &left_point, &selected_point)) != NULL){
  88.         delete_splinearrow(spline);
  89.         }
  90.     else if ((arc = arc_point_search(x, y, TOLERANCE, 
  91.         &arcpoint_num)) != NULL) {
  92.         delete_arcarrow(arc);
  93.         }
  94.     else
  95.         return;
  96.  
  97.     set_modifiedflag();
  98.     }
  99.  
  100. add_linearrow(line)
  101. F_line    *line;
  102. {
  103.     F_point    *p;
  104.  
  105.     if (line->type == T_POLYGON || line->type == T_BOX) return;
  106.     if (line->points->next == NULL) return;    /* A single point line */
  107.  
  108.     if (left_point == NULL) { /*  selected_point is the first point */
  109.         if (line->back_arrow) return;
  110.         p = selected_point->next;
  111.         line->back_arrow = backward_arrow();
  112.         if (pointmarker_shown) toggle_linepointmarker(line);
  113.         draw_arrow(p->x, p->y, selected_point->x, selected_point->y, 
  114.             line->back_arrow, PAINT);
  115.         if (pointmarker_shown) toggle_linepointmarker(line);
  116.         }
  117.     else if (selected_point->next == NULL) { /* forward arrow */
  118.         if (line->for_arrow) return;
  119.         line->for_arrow = forward_arrow();
  120.         if (pointmarker_shown) toggle_linepointmarker(line);
  121.         draw_arrow(left_point->x, left_point->y, 
  122.             selected_point->x, selected_point->y, 
  123.             line->for_arrow, PAINT);
  124.         if (pointmarker_shown) toggle_linepointmarker(line);
  125.         }
  126.     clean_up();
  127.     set_action_object(F_ADD_ARROW_HEAD, O_POLYLINE);
  128.     }
  129.  
  130. add_arcarrow(arc)
  131. F_arc    *arc;
  132. {
  133.  
  134.     if (arcpoint_num == 0) { /*  backward arrow  */
  135.         if (arc->back_arrow) return;
  136.         arc->back_arrow = backward_arrow();
  137.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  138.         draw_arcarrow(arc, foreground_color);
  139.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  140.         }
  141.     else if (arcpoint_num == 2) { /*  for_arrow  */
  142.         if (arc->for_arrow) return;
  143.         arc->for_arrow = forward_arrow();
  144.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  145.         draw_arcarrow(arc, foreground_color);
  146.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  147.         }
  148.     clean_up();
  149.     set_action_object(F_ADD_ARROW_HEAD, O_ARC);
  150.     }
  151.  
  152. add_splinearrow(spline)
  153. F_spline    *spline;
  154. {
  155.     F_point        *p;
  156.     F_control    *c;
  157.  
  158.     if (closed_spline(spline)) return;
  159.     if (left_point == NULL) { /* add backward arrow */
  160.         if (spline->back_arrow) return;
  161.         p = selected_point->next;
  162.         spline->back_arrow = backward_arrow();
  163.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  164.         if (normal_spline(spline)) {
  165.         draw_arrow(p->x, p->y, selected_point->x,
  166.             selected_point->y, spline->back_arrow, PAINT);
  167.         }
  168.         else {
  169.         c = spline->controls;
  170.         draw_arrow(round(c->rx), round(c->ry), selected_point->x,
  171.             selected_point->y, spline->back_arrow, PAINT);
  172.         }
  173.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  174.         }
  175.     else if (selected_point->next == NULL) { /* add forward arrow */
  176.         if (spline->for_arrow) return;
  177.         spline->for_arrow = forward_arrow();
  178.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  179.         if (normal_spline(spline)) {
  180.         draw_arrow(left_point->x, left_point->y,
  181.             selected_point->x, selected_point->y,
  182.             spline->for_arrow, PAINT);
  183.         }
  184.         else {
  185.         for (c = spline->controls; c->next != NULL; c = c->next);
  186.         draw_arrow(round(c->lx), round(c->ly), selected_point->x,
  187.             selected_point->y, spline->for_arrow, PAINT);
  188.         }
  189.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  190.         }
  191.     clean_up();
  192.     set_action_object(F_ADD_ARROW_HEAD, O_SPLINE);
  193.     }
  194.  
  195. delete_linearrow(line)
  196. F_line    *line;
  197. {
  198.     if (line->type == T_POLYGON || line->type == T_BOX) return;
  199.  
  200.     if (left_point == NULL) { /*  selected_point is the first point */
  201.         if (! line->back_arrow) return;
  202.         if (pointmarker_shown) toggle_linepointmarker(line);
  203.         draw_line(line, INV_PAINT);
  204.         line->back_arrow = 0;
  205.         free((char*)line->back_arrow);
  206.         line->for_arrow = NULL;
  207.         draw_line(line, PAINT);
  208.         if (pointmarker_shown) toggle_linepointmarker(line);
  209.         }
  210.     else if (selected_point->next == NULL) { /* forward arrow */
  211.         if (! line->for_arrow) return;
  212.         if (pointmarker_shown) toggle_linepointmarker(line);
  213.         draw_line(line, INV_PAINT);
  214.         free((char*)line->for_arrow);
  215.         line->for_arrow = NULL;
  216.         draw_line(line, PAINT);
  217.         if (pointmarker_shown) toggle_linepointmarker(line);
  218.         }
  219.     clean_up();
  220.     set_action_object(F_DELETE_ARROW_HEAD, O_POLYLINE);
  221.     }
  222.  
  223. delete_arcarrow(arc)
  224. F_arc    *arc;
  225. {
  226.     if (arcpoint_num == 0) { /*  backward arrow  */
  227.         if (! arc->back_arrow) return;
  228.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  229.         draw_arc(arc, background_color);
  230.         free((char*)arc->back_arrow);
  231.         arc->back_arrow = NULL;
  232.         draw_arc(arc, foreground_color);
  233.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  234.         }
  235.     else if (arcpoint_num == 2) { /*  for_arrow  */
  236.         if (! arc->for_arrow) return;
  237.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  238.         draw_arc(arc, background_color);
  239.         free((char*)arc->for_arrow);
  240.         arc->for_arrow = NULL;
  241.         draw_arc(arc, foreground_color);
  242.         if (pointmarker_shown) toggle_arcpointmarker(arc);
  243.         }
  244.     clean_up();
  245.     set_action_object(F_DELETE_ARROW_HEAD, O_ARC);
  246.     }
  247.  
  248. delete_splinearrow(spline)
  249. F_spline    *spline;
  250. {
  251.     F_point    *p;
  252.  
  253.     if (closed_spline(spline)) return;
  254.     if (left_point == NULL) { /*  selected_point is the first point */
  255.         if (! spline->back_arrow) return;
  256.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  257.         p = selected_point->next;
  258.         if (normal_spline(spline)) {
  259.         draw_arrow(p->x, p->y, selected_point->x,
  260.             selected_point->y, spline->back_arrow, ERASE);
  261.         pw_vector(canvas_pixwin, selected_point->x, selected_point->y,
  262.             round((p->x+selected_point->x)/2.0),
  263.             round((p->y+selected_point->y)/2.0), PAINT, 1);
  264.         }
  265.         else {
  266.         F_control    *a, *b;
  267.  
  268.         a = spline->controls;
  269.         b = a->next;
  270.         draw_arrow(round(a->rx), round(a->ry), selected_point->x,
  271.             selected_point->y, spline->back_arrow, ERASE);
  272.         bezier_spline(
  273.             (float)selected_point->x, (float)selected_point->y,
  274.             a->rx, a->ry, b->lx, b->ly, (float)p->x, (float)p->y,
  275.             PAINT);
  276.         }
  277.         free((char*)spline->back_arrow);
  278.         spline->back_arrow = NULL;
  279.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  280.         }
  281.     else if (selected_point->next == NULL) { /* forward arrow */
  282.         if (! spline->for_arrow) return;
  283.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  284.         if (normal_spline(spline)) {
  285.         draw_arrow(left_point->x, left_point->y,
  286.             selected_point->x, selected_point->y,
  287.             spline->for_arrow, ERASE);
  288.         pw_vector(canvas_pixwin, selected_point->x, selected_point->y,
  289.             round((selected_point->x+left_point->x)/2.0),
  290.             round((selected_point->y+left_point->y)/2.0),
  291.             PAINT, 1);
  292.         }
  293.         else {
  294.         F_control    *a, *b;
  295.  
  296.         a = spline->controls;
  297.         for (b = a->next; b->next != NULL; a = b, b = b->next);
  298.         draw_arrow(round(b->lx), round(b->ly), selected_point->x,
  299.             selected_point->y, spline->for_arrow, ERASE);
  300.         bezier_spline(
  301.             (float)left_point->x, (float)left_point->y,
  302.             a->rx, a->ry, b->lx, b->ly,
  303.             (float)selected_point->x, (float)selected_point->y,
  304.             PAINT);
  305.         }
  306.         free((char*)spline->for_arrow);
  307.         spline->for_arrow = NULL;
  308.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  309.         }
  310.     clean_up();
  311.     set_action_object(F_DELETE_ARROW_HEAD, O_SPLINE);
  312.     }
  313.